<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<div>
	&nbsp;&nbsp;&nbsp; 说明：请在下面输入你要添加的信息，带
	<span style="color: red">*</span>为必填内容
</div>

<form action="../writeInsertDonate" method="post" name="insertDonateForm">
	<table cellpadding="4" cellspacing="0" width="600" align="center">
		<tr>
			<td>
				<table width="100">
					<tr>
						<td>
							&nbsp;
						</td>
					</tr>
				</table>
			</td>
		</tr>
		<tr>
			<td align="left" width="130">
				捐赠名称：
			</td>
			<td>
				<input type="text" name="insertDonateName" id="insertDonateName"
					size="35" />
				<span style="color: red">*</span>
			</td>
		</tr>
		<tr>
			<td align="left" width="130">
				捐赠金额：
			</td>
			<td>
				<input type="text" name="insertDonatePrice" id="insertDonatePrice"
					size="35" />元
				<span style="color: red">*</span> 最低1元,最多精确到分
			</td>
		</tr>
		<tr>
			<td align="left" width="130">
				捐赠项目或用途：
			</td>
			<td>
				<!--				<input type="text" name="insertDonateNeed" id="insertDonateNeed"-->
				<!--					value="${modifyDonate.donate_need }" size="35" />-->
				<select name="choice_project_title">
					<option value="无指定用途">
						无指定用途
					</option>
					<c:forEach items="${project_title_list}" var="project_title">
						<option value="${project_title}">${project_title}</option>
					</c:forEach>
				</select>
			</td>
		</tr>
		<tr>
			<td align="left" width="130">
				捐赠者邮箱：
			</td>
			<td>
				<input type="text" name="insertDonateEmail" id="insertDonateEmail"
					size="35" />
				<span style="color: red">*</span>
			</td>
		</tr>
		<tr>
			<td align="left" width="130">
				捐赠者电话号码：
			</td>
			<td>
				<input type="text" name="insertDonateTelephone"
					id="insertDonateTelephone" size="35" />
				&nbsp;&nbsp;11位手机号码
			</td>
		</tr>
		<tr>
			<td align="left" width="130">
				捐赠者地址：
			</td>
			<td>
				<input type="text" name="insertDonateAddress"
					id="insertDonateAddress" size="35" />
			</td>
		</tr>
		<tr>
			<td align="left" width="130">
				捐赠者邮政编码：
			</td>
			<td>
				<input type="text" name="insertDonatePostalcode"
					id="insertDonatePostalcode" size="35" />
			</td>
		</tr>
		<tr>
			<td align="left" width="130">
				是否校友：
			</td>
			<td>
				<input type="radio" name="insertDonateAlumni"
					id="insertDonateAlumniYes" value="yes" checked
					onclick=
	moodifyHideYes();
/>
				校友
				<input type="radio" name="insertDonateAlumni"
					id="insertDonateAlumniNo" value="no" onclick=
	moodifyHideNo();
/>
				非校友
			</td>
		</tr>
		<tr id="insertTr">
			<td align="left" width="130">
				<div id="">
					入校时间及院部：
				</div>
			</td>
			<td>
				<input type="text" name="insertDonateClassInformation"
					id="insertDonateClassInformation" size="35" />
				<span style="color: red">*</span>
			</td>
		</tr>
		<tr>
			<td align="left" width="130">
				捐赠者留言：
			</td>
			<td>
				<textarea rows="10" cols="50" name="insertDonateRemark"></textarea>
			</td>
		</tr>
		<tr>
			<td style="padding-left: 200" colspan="2">
				<input type="button" value="提交" onclick=
	submitInsertDonatecheck();
name="insertDonateButton" id="insertDonateButton" />
			</td>
		</tr>
	</table>
</form>

<script type="text/javascript">
	function moodifyHideYes() {
		document.getElementById("insertTr").style.display="none";
		document.getElementById("insertTr").style.display="";
	}
	function moodifyHideNo() {
		document.getElementById("insertTr").style.display="";
		document.getElementById("insertTr").style.display="none";
	}

	function submitInsertDonatecheck() {
		var name = document.insertDonateForm.insertDonateName.value;
		var price = document.insertDonateForm.insertDonatePrice.value;
		var email = document.insertDonateForm.insertDonateEmail.value;
		var telephone = document.insertDonateForm.insertDonateTelephone.value;
		var postalcode = document.insertDonateForm.insertDonatePostalcode.value;
		var alumni = "";

		for(var i=0;i<document.insertDonateForm.insertDonateAlumni.length;i++) {
			if(document.insertDonateForm.insertDonateAlumni[i].checked) {
				alumni = document.insertDonateForm.insertDonateAlumni[i].value;
			}
		}

		var regexPrice1 = /^[1-9][0-9]*$/;
		var regexPrice2 = /^[1-9][0-9]*\.[0-9]{2}$/;
		var regexEmail = /^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/;
		var regexTelePhone = /^[1][3-8][0-9]{9}$/;
		var regexPostcode = /^[1-9][0-9]{5}$/;
		
		if (name == "") {
			alert("输入的捐赠名称不能为空!");
		} else if (price == "") {
			alert("输入的捐赠金额不能为空!");
		} else if (!regexPrice1.test(price) && !regexPrice2.test(price)) {
			alert("输入的捐赠金额格式不正确!")
		} else if (email == "") {
			alert("输入的邮箱不能为空!")
		} else if (!regexEmail.test(email)) {
			alert("输入的邮箱格式不正确!")
		} else if (telephone != "" && !regexTelePhone.test(telephone)) {
			alert("输入的电话号码格式不正确!")
		} else if (postalcode != "" && !regexPostcode.test(postalcode)) {
			alert("输入的邮政编码格式不正确!");
		} else if (alumni == "yes") {
			var classInformation = document.insertDonateForm.insertDonateClassInformation.value;
			if (classInformation == "") {
				alert("输入的入校时间及院部不能为空!")
			} else {
				document.insertDonateForm.submit();
			}
		} else {
			document.insertDonateForm.submit();
		}
	}
</script>